$(function() {
    $('.skin-minimal input').iCheck({
        checkboxClass: 'icheckbox-blue',
        radioClass: 'iradio-blue',
        increaseArea: '20%'
    });

    $("#form-lisence-add").validate({
        rules: {
            userName: {
                required: true,
                minlength: 2,
                maxlength: 10
            },
            passWord: {
                required: true,
                minlength: 3,
                maxlength: 16
            },
            orgCode: {
                required: true,
                minlength: 2,
                maxlength: 10
                // isContainsSpecialChar: false
            },
            count: {
                required: true,
                digits: true
            },
            roleId: {
                required: true,
            },
        },
        onkeyup: false,
        focusCleanup: true,
        success: "valid",
        submitHandler:function(form){
            var userName = $("#userName").val();
            if($.trim(userName) == ""){
                layer.msg("请输入合法的用户名",{icon:2,time:4000});
                return;
            }
            $.ajax({
                type: "POST",
                url: '/authorize/addLisence',
                data: $('#form-lisence-add').serialize(),
                success: function (data) {
                    // var data = eval("(" + data + ")");
                    if (data.success == true) {
                        layer.msg(data.msg,{icon:1,time:2000},function(){
                            parent.location.reload();
                            //注意: 关闭打开的添加页 无法实现刷新 现修改为刷新父页面
                            // var index = parent.layer.getFrameIndex(window.name);
                            // parent.$('.btn-refresh').click();
                            // parent.layer.close(index);
                        });
                    } else if(data.success == false){
                        layer.msg(data.msg,{icon:2,time:4000});
                        return;
                    }
                }
            });
        }
    });
});